/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package io.renren.common.utils;

import java.text.SimpleDateFormat;
import java.util.UUID;

/**
 * 封装各种生成唯一性ID算法的工具类.
 * 
 * @version 2016-01-15
 */
public class IdGen {

	public static int Guid = 1000;

	/**
	 * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
	 */
	public static String uuid() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

	public static String id() {

		IdGen.Guid += 1;

		long now = System.currentTimeMillis();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		// 获取时间戳
		String time = dateFormat.format(now);
		String info = now + "";
		String id = info.substring(info.length() - 6);
		int ran = 0;
		if (IdGen.Guid > 9999) {
			IdGen.Guid = 1000;
		}
		ran = IdGen.Guid;
		return id + ran;
	}

}
